﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Maticsoft.DBUtility;

namespace ElingOA6_DSJCJ.DAL
{
    /// <summary>
    /// 部门数据类
    /// </summary>
    public class HRDept
    {
        public HRDept()
        {
        }
        /// <summary>
        /// 获取某单位所有部门的编号、名称、上级的编号
        /// <creator>wangl</creator>
        /// <date>2013-09-10</date>
        /// </summary>
        /// <param name="entityNO"></param>
        /// <returns></returns>
        public DataSet GetAllDeptNoAndName(string entityNO)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FDeptNo,FDeptName,FParentDeptNo from t_HRDept");
            strSql.Append(" where FEntityNo=@FEntityNo");

            SqlParameter[] parameters = { 
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar, 15)};
            parameters[0].Value = entityNO;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        public DataSet  GetAllDeptByEntityNoFIsAgency(string entityNO)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FDeptNo,FDeptName,FParentDeptNo from t_HRDept");
            strSql.Append(" where FEntityNo=@FEntityNo and FIsAgency='Y'");

            SqlParameter[] parameters = { 
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar, 15)};
            parameters[0].Value = entityNO;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        public bool IsFIsAgencyByDeptNo(string deptno)
        {
            string strsql = "SELECT COUNT(*) FROM dbo.t_HRDept WHERE FDeptNo='" + deptno + "' AND FIsAgency='Y'";
            return DbHelperSQL.Exists(strsql);
        }
        public string GetFShowContent(string entityNO ,string FDeptNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FShowContent from dbo.t_DeptShowContent");
            strSql.Append(" where FEntityNo=@FEntityNo and FDeptNo=@FDeptNo");
            SqlParameter[] parameters ={
                    new SqlParameter("@FEntityNo",SqlDbType.NVarChar,12),
                    new SqlParameter("@FDeptNo",SqlDbType.NVarChar,12)};
            parameters[0].Value = entityNO;
            parameters[1].Value = FDeptNo;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (null != obj)
            {
                return obj.ToString();
            }
            else
            {
                return string.Empty;
            }
        }
        /// <summary>
        /// 获取部门名称
        /// <creator>wangl</creator>
        /// <date>2013-09-25</date>
        /// </summary>
        /// <param name="fEntityNo">组织机构编号</param>
        /// <param name="fDeptNo">部门编号</param>
        /// <returns>部门名称</returns>
        public string GetDeptName(string entityNo, string deptNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FDeptName from dbo.v_HRDept");
            strSql.Append(" where FEntityNo=@FEntityNo and FDeptNo=@FDeptNo");
            SqlParameter[] parameters ={
                    new SqlParameter("@FEntityNo",SqlDbType.NVarChar,12),
                    new SqlParameter("@FDeptNo",SqlDbType.NVarChar,12)};
            parameters[0].Value = entityNo;
            parameters[1].Value = deptNo;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (null != obj)
            {
                return obj.ToString();
            }
            else
            {
                return string.Empty;
            }
        }
    }
}
